
//
//  LayoutView.m
//  for_test
//
//  Created by Carlson Lee on 2017/7/5.
//  Copyright © 2017年 Carlson Lee. All rights reserved.
//

#import "LayoutView.h"

@implementation LayoutView

- (void)prepareLayout
{
    [super prepareLayout];
    self.itemSize = CGSizeMake(150, 100);
    
    self.minimumLineSpacing = 50;
    CGSize vsz = self.collectionView.frame.size;
    CGFloat f_top = 50;
    CGFloat f_gap = (vsz.height-self.itemSize.height*2-self.minimumLineSpacing)/2;
    self.sectionInset = UIEdgeInsetsMake(f_top, 0, f_gap, 0);
    
//    CGFloat inset = (vsz.width-self.itemSize.width)/2;
//    self.collectionView.contentInset = UIEdgeInsetsMake(0, inset, 0, inset);
}

//- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds
//{
//    return YES;
//}

//- (nullable NSArray<__kindof UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect
//{
//    NSArray* arrs = [super layoutAttributesForElementsInRect:rect];
//    
//    CGRect visibleRect;
//    visibleRect.origin = self.collectionView.contentOffset;
//    visibleRect.size = self.collectionView.frame.size;
//    
//    CGFloat centerX = CGRectGetMidX(visibleRect);
//    CGFloat MAX_WIDTH = 100.0;
//    for(UICollectionViewLayoutAttributes* attr in arrs){
//        if(CGRectIntersectsRect(visibleRect, attr.frame)){
//            CGFloat scale;
//            if(ABS(attr.center.x - centerX)>MAX_WIDTH){
//                scale = 1;
//            }else{
//                scale = 1 + 0.2*(1-ABS(attr.center.x-centerX)/MAX_WIDTH);
//            }
//            attr.transform = CGAffineTransformMakeScale(scale, scale);
//        }
//    }
//    
//    return arrs;
//}

//- (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset withScrollingVelocity:(CGPoint)velocity
//{
//    CGRect lastRect;
//    lastRect.origin = proposedContentOffset;
//    lastRect.size = self.collectionView.frame.size;
//    
//    NSArray* array = [self layoutAttributesForElementsInRect:lastRect];
//    
//    CGFloat centerX = CGRectGetMidX(lastRect);
//    CGFloat minX = CGFLOAT_MAX;
//    for(UICollectionViewLayoutAttributes* attrs in array){
//        if(ABS(attrs.center.x - centerX) < ABS(minX)){
//            minX = attrs.center.x- centerX;
//        }
//    }
//    return CGPointMake(proposedContentOffset.x + minX, proposedContentOffset.y);
//}

@end
